package cool.tianyou.blue.bird.util;

import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;


public class JsonReturn {
    private Integer code;
    private String msg;
    private Map<String,Object> map;

    public JsonReturn() {
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public JsonReturn setMap(Map<String, Object> map) {
        this.map = map;
        return this;
    }

    public JsonReturn(String msg, Integer code){
        this.map = new HashMap<>();
        this.msg = msg;
        this.code = code;
    }

    public JsonReturn put(String key,Object value) {
        this.map.put(key, value);
        return this;
    }

    public static JsonReturn ok(){
        JsonReturn jsonReturn =new JsonReturn("success",200);
        return jsonReturn;
    }
    public static JsonReturn error(){
        JsonReturn jsonReturn =new JsonReturn("error",100);
        return jsonReturn;
    }

    public static JsonReturn error(String msg,Integer code){
        JsonReturn jsonReturn =new JsonReturn(msg,code);
        return jsonReturn;
    }
    public static JsonReturn error(String msg){
        JsonReturn jsonReturn =new JsonReturn(msg,100);
        return jsonReturn;
    }

    public String toJson(){
        return JSONObject.toJSONString(this);
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }


    public Map<String, Object> getMap() {
        return map;
    }
}
